<?php
include('check_session.php');
//Salva no banco

#incluindo a classe conexao (supondo estar no mesmo diretorio)
include('conexao.class.php');

$mensagem = '';

if($_POST){
#instanciando o objeto 
$minhaConexao = new Conexao();

#chamada ao metodo open que abra a conexao
$minhaConexao->open();

$descricao = $_POST['data']['ContaContabil']['descricao'];
$vida_util = $_POST['data']['ContaContabil']['vida_util'];
$taxa_residual = $_POST['data']['ContaContabil']['taxa_residual'];
$result = pg_query("INSERT INTO conta_contabils(descricao, vida_util, taxa_residual, userinc, datainc)
    VALUES ('$descricao', $vida_util, $taxa_residual, 0, now());");

if($result)
	$mensagem = 'Registro cadastrado com sucesso!';
else
	$mensagem = 'Ocorreu um erro durante a operação. Por favor, tente novamente!';
#encerrando a conexao 
$minhaConexao->close();
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />	<title>
		SIDEP: Sistema de Depreciação:
		Cadastro de Contas	</title>
	<link href="http://localhost/sidep/conta_contabils/width=device-width, initial-scale=1.0" type="application/rss+xml" rel="alternate" title="viewport" />
	<meta name="description" content="Sistema de Depreciação de Bens Materiais" />
	<link href="http://localhost/sidep/conta_contabils/Diovane Monteiro, Renan Reis, Kathlen Brum" type="application/rss+xml" rel="alternate" title="author" />
	<!-- <link href="/sidep/favicon.ico" type="image/x-icon" rel="icon" /><link href="/sidep/favicon.ico" type="image/x-icon" rel="shortcut icon" />-->
	<link rel="stylesheet" type="text/css" href="css/bootstrap.css" /><link rel="stylesheet" type="text/css" href="/sidep/css/bootstrap-responsive.css" />
	<link rel="stylesheet" type="text/css" href="css/bootstrap-custom.css" /><link rel="stylesheet" type="text/css" href="/sidep/css/bootstrap-responsive-custom.css" />
	<link rel="stylesheet" type="text/css" href="css/sidep.css" /><script type="text/javascript" src="/sidep/js/jquery-1.7.2.js"></script>	
	<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
	<!--[if lt IE 9]>
	<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
	
</head>
<body>
    <div class="container">
    
      <div class="row">
			<div class="page">

			
	<div class="page-header">
		
		<h2>Cadastro de Contas</h2>
		
		<div class="page-header-fields">
			<a href="#" class="btn btn-primary"><i class="icon-user icon-white"></i> Boa noite, Sr(a). <?php echo $_SESSION['usuario']['nome']; ?></a>
			<a href="lista.php" class="btn btn-primary"><i class="icon-th-list icon-white"></i> Listar Contas</a>
			<a href="logout.php" class="btn btn-danger"><i class="icon-off icon-white"></i>Sair</a>
				
		</div>
	</div>

	<div class="page-content">	
			<?php if(!empty($mensagem)):?>
				<div class="alert alert-success">
				<?php echo $mensagem; ?>
				</div>
			<?php endif;?>
		<form action="cadastro.php" class="form-horizontal" id="ContaContabilAddForm" method="post" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST"/></div>			<fieldset>

				<legend>Dados Cadastrais</legend>

				<div class="control-group">
				
					<label for="ContaContabilDescricao" class="control-label">Descrição</label>					<div class="controls">

		              <input name="data[ContaContabil][descricao]" class="input-xxlarge" type="text" id="ContaContabilDescricao"/>		            </div>

				</div>

				<div class="control-group">

					<label for="ContaContabilVidaUtil" class="control-label">Vida Útil</label>					<div class="controls">

		              <input name="data[ContaContabil][vida_util]" type="number" id="ContaContabilVidaUtil"/>		            </div>

				</div>

				<div class="control-group">

					<label for="ContaContabilTaxaResidual" class="control-label">Taxa Residual</label>					<div class="controls">

		              <input name="data[ContaContabil][taxa_residual]" step="any" type="number" id="ContaContabilTaxaResidual"/>		            </div>

				</div>

				<div class="form-actions">

		            <input  class="btn btn-primary" type="submit" value="Salvar"/>	          	</div>

			</fieldset>

		</form>   </div>

   <div class="page-footer"></div>

</div>


      </div><!--/row-->

      <hr/>

    </div><!--/.fluid-container-->
	</body>
</html>
